import { NODE_CONFIG, type NodeShapeType } from '@/config/node.config'
import { getDictListForKey } from '@/utils/dict'
import { Node } from '@antv/x6'
export const getTransferNodeConfig = (node:Node) => {
  const { x, y } = node.position()
  const { width, height } = node.size()
  const angle = node.getAngle()
  const data = node.getData()

  return {
    ...data,
    startX: x,
    startY: y,
    width: width,
    height: height,
    rotate: angle
  }
}

export const getNodeListForModules = (list = []) => {
  const typeList = getDictListForKey('CANVASASSEMBLYTYPE')
  const nodeList:any[] = []
  list.forEach((data:any) => {
    const type = typeList.find(v => v.itemValue === data.contentType)
    if (type) {
      const shape = type.itemValue
      const config = NODE_CONFIG[shape as NodeShapeType].config
      const node:{[key: string]: any; } = {}
      for (const key in config.data) {
        if (['fontBold', 'fontItalic'].includes(key)) {
          node[key] = !!data[key]
        } else {
          node[key] = data[key]
        }
      }
      nodeList.push({
        shape,
        id: data.id,
        zIndex: node.rankIndex,
        x: Number(node.startX),
        y: Number(node.startY),
        width: Number(node.width),
        height: Number(node.height),
        data: node
      })
    } else {
      console.log('不存在节点', data.contentType)
    }
  })
  return nodeList
}
